package com.bysj.studentsystem.controller;

import com.bysj.studentsystem.vo.ResponseDataVO;
import com.bysj.studentsystem.entity.SysDormitory;
import com.bysj.studentsystem.service.SysDormitoryService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (SysDormitory)宿舍管理控制层
 *
 * @author makejava
 * @since 2024-03-09 16:51:43
 */
@CrossOrigin
@RestController
@RequestMapping("/dormitory")
public class SysDormitoryController {
    /**
     * 服务对象
     */
    @Resource
    private SysDormitoryService sysDormitoryService;


    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping
    public ResponseDataVO<PageInfo<SysDormitory>> queryByPage(@RequestParam(value = "id", required = false) Integer id,
                                                              @RequestParam(value = "code", required = false) String code,
                                                              @RequestParam(value = "commendContent", required = false) String commendContent,
                                                              @RequestParam(value = "disposalContent", required = false) String disposalContent,
                                                              @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                                              @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        if (pageNum == null || pageSize == null) {
            pageNum = 1;
            pageSize = 10;
        }
        SysDormitory sysDormitory = new SysDormitory();
        sysDormitory.setId(id);
        sysDormitory.setCode(code);
        sysDormitory.setCommendContent(commendContent);
        sysDormitory.setDisposalContent(disposalContent);
        return new ResponseDataVO().ok(this.sysDormitoryService.queryByPage(sysDormitory, pageNum, pageSize));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseDataVO<SysDormitory> queryById(@PathVariable("id") Integer id) {
        return new ResponseDataVO().ok(this.sysDormitoryService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysDormitory 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseDataVO<SysDormitory> add(SysDormitory sysDormitory) {
        return new ResponseDataVO().ok(this.sysDormitoryService.insert(sysDormitory));
    }

    /**
     * 编辑数据
     *
     * @param sysDormitory 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseDataVO<SysDormitory> edit(SysDormitory sysDormitory) {
        return new ResponseDataVO().ok(this.sysDormitoryService.update(sysDormitory));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseDataVO<Boolean> deleteById(Integer id) {
        return new ResponseDataVO().ok(this.sysDormitoryService.deleteById(id));
    }

}

